﻿using System;
using EasyStep.Attributes;using EasyStep.TestExecution.Data;using EasyStep.TestExecution.Interfaces;

using OpenQA.Selenium;

namespace EasyStep.TestActions.Actions.Fill
{
    [TestAction(typeof(Fill),  Name = "ById")]
    class FillById : ITestAction<IWebDriver>
    {
        public void Execute(IWebDriver browser, TestStepResult data, IExecuteDataContext context)
        {
            try
            {
                browser.FindElement(By.Id(data.Locator)).Clear();
                browser.FindElement(By.Id(data.Locator)).SendKeys(data.Data);
            }
            catch (Exception ex)
            {
               data.Result = TestExecution.ExecutionResult.Failed;
               data.ExecutionLog.AppendFormat("Can't Fill element id=[{0}] with data:{1}\r\n{2}",data.Locator,data.Data, ex.Message);
               context.Log.Error("Can't fill element by Id:"+data.Locator, ex);
            }
        }

    }
}